<?php

/**
 * This is the model class for table "tb_usuario".
 *
 * The followings are the available columns in table 'tb_usuario':
 * @property integer $ID_USUARIO
 * @property string $NOME_USUARIO
 * @property string $EMAIL_USUARIO
 * @property string $SENHA_USUARIO
 * @property integer $TB_ARMAZEM_ID_ARMAZEM
 *
 * The followings are the available model relations:
 * @property TbArmazem $tBARMAZEMIDARMAZEM
 */
class Usuario extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Usuario the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tb_usuario';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			//array('NOME_USUARIO, EMAIL_USUARIO, SENHA_USUARIO, TB_ARMAZEM_ID_ARMAZEM', 'required'),
			array('NOME_USUARIO, EMAIL_USUARIO, SENHA_USUARIO', 'required'),
			array('TB_ARMAZEM_ID_ARMAZEM', 'numerical', 'integerOnly'=>true),
			array('NOME_USUARIO, EMAIL_USUARIO', 'length', 'max'=>100),
			array('SENHA_USUARIO', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_USUARIO, NOME_USUARIO, EMAIL_USUARIO, SENHA_USUARIO, TB_ARMAZEM_ID_ARMAZEM', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
				'Armazem' => array(self::BELONGS_TO, 'Armazem', 'TB_ARMAZEM_ID_ARMAZEM'),
	
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_USUARIO' => 'Id Usuario',
			'NOME_USUARIO' => 'Usuário',
			'EMAIL_USUARIO' => 'Email',
			'SENHA_USUARIO' => 'Senha',
			'TB_ARMAZEM_ID_ARMAZEM' => 'Armazem',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		
		$criteria=new CDbCriteria;

		$criteria->compare('ID_USUARIO',$this->ID_USUARIO);
		$criteria->compare('NOME_USUARIO',$this->NOME_USUARIO,true);
		$criteria->compare('EMAIL_USUARIO',$this->EMAIL_USUARIO,true);
		$criteria->compare('SENHA_USUARIO',$this->SENHA_USUARIO,true);
		$criteria->compare('TB_ARMAZEM_ID_ARMAZEM',$this->TB_ARMAZEM_ID_ARMAZEM);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	//traz lista de armazens para dropDown
	public function getArmazemOptions(){

	    return CHtml::listData(Armazem::model()->findAll(),'ID_ARMAZEM','NOME_ARMAZEM');
	
	}
	
}